package com.example.rdemo.controller;


import com.example.rdemo.entity.Shop;
import com.example.rdemo.service.ShopService;
import com.example.rdemo.utils.PageResult;
import com.example.rdemo.utils.PassToken;
import com.example.rdemo.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * shopController
 * 
 * @author ruoyi
 * @date 2025-04-01
 */
@RestController
@RequestMapping("/system/shop")
public class ShopController{
    @Autowired
    private ShopService shopService;

    //查询shop列表
    @PassToken
    @GetMapping("/list")
    public ResponseResult list(Shop shop, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) {
//        startPage();
        PageResult pageResult = shopService.selectShopList(shop,pageNum,pageSize);
        return ResponseResult.createBySuccess(200,pageResult,"查询成功");
    }
    @PassToken
    @GetMapping("/list1")
    public ResponseResult list1(Shop shop, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) {
        PageResult pageResult = shopService.selectShopGoodsList(shop,pageNum,pageSize);
        return ResponseResult.createBySuccess(200,pageResult,"查询成功");
    }

    //导出shop列表
//    @PreAuthorize("@ss.hasPermi('system:shop:export')")
//    @Log(title = "shop", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Shop shop)
//    {
//        List<Shop> list = shopService.selectShopList(shop);
//        ExcelUtil<Shop> util = new ExcelUtil<Shop>(Shop.class);
//        util.exportExcel(response, list, "shop数据");
//    }

    //获取shop详细信息
    @GetMapping(value = "/{cid}")
    public ResponseResult getInfo(@PathVariable("cid") Long cid) {
        Shop shop = shopService.selectShopByCid(cid);
        return ResponseResult.createBySuccess(200,shop,"查询成功");
    }

    //新增shop
    @PostMapping
    public ResponseResult add(@RequestBody Shop shop) {
        int i = shopService.insertShop(shop);
        if(i>0){
            return ResponseResult.createBySuccess(200,"","添加成功");
        }else {
            return ResponseResult.createByFail(500,"添加失败");
        }
    }

    //修改shop
    @PutMapping
    public ResponseResult edit(@RequestBody Shop shop) {
        int i = shopService.updateShop(shop);
        if(i>0){
            return ResponseResult.createBySuccess(200,"","更新成功");
        }else {
            return ResponseResult.createByFail(500,"更新");
        }
    }

    //删除shop
	@DeleteMapping("/{cids}")
    public ResponseResult remove(@PathVariable Long[] cids) {
        int i = shopService.deleteShopByCids(cids);
        if(i>0){
            return ResponseResult.createBySuccess(200,"","删除成功");
        }else {
            return ResponseResult.createByFail(500,"删除失败");
        }
    }
}
